Type.registerNamespace("Telerik.Web.UI");
Type.registerNamespace("Telerik.Web.UI.Scheduler");
(function(){var d=$telerik.$;
var b=Telerik.Web.UI;
var e=Telerik.Web.UI.Scheduler;
var a=60000;
var c=a*60;
var f=c*24;
var g;
e.ResourceGroupedWeekModel=function(h,j,i){e.ResourceGroupedWeekModel.initializeBase(this,[h]);
this._weekModels=new Array();
this._resources=new b.SchedulerResourceCollection();
this._groupingResource=j;
this._isVertical=i;
if(e.Rendering.BlockCollection){this._blockCollection=new e.Rendering.BlockCollection();
}if(e.Rendering.HorizontalBlockCollection){this._allDayBlocks=new e.Rendering.HorizontalBlockCollection();
}};
e.ResourceGroupedWeekModel.prototype={initialize:function(){this._resources=this._owner.get_resources().getResourcesByType(this._groupingResource);
for(var h=0;
h<this._resources.get_count();
h++){this._weekModels[h]=this._createNestedModel();
}},getTimeSlotFromDomElement:function(j){var m=60*24;
var i=this._getRawIndexFromDomElement(j);
var h=this._getTimeFromDomElement(j);
var l=this._resources.getResource(i.modelIndex);
var k=(i.viewPartIndex==0)?m:this._owner.get_minutesPerRow();
return new e.ResourceGroupedWeekTimeSlot(i,h,k,l,j);
},getTimeSlotForAppointment:function(p){var j=this._getAppointmentModelIndex(p);
if(j==-1){return null;
}var i=p.get_duration()%f==0;
var h=i?0:1;
var k;
if(i){k=this._weekModels[0]._getAllDayTimeSlotIndices(p.get_start());
}else{k=this._weekModels[0]._getRegularTimeSlotIndices(p.get_start());
}k.viewPartIndex=h;
k.modelIndex=j;
var m=this._weekModels[0]._getTimeFromIndex(k);
var l=60*24;
var o=(k.viewPartIndex==0)?l:this._owner.get_minutesPerRow();
var n=this._getTimeSlotDomElement(h,k.rowIndex,k.cellIndex,j);
return new e.ResourceGroupedWeekTimeSlot(k,m,o,this._resources.getResource(j),n);
},isVisible:function(h){var i=e.ResourceGroupedWeekModel.callBaseMethod(this,"isVisible",[h]);
var j=this._getAppointmentModelIndex(h)!=-1;
return i&&j;
},_getAppointmentModelIndex:function(h){var i=-1;
var j=this;
h.get_resources().forEach(function(k){var l=j._resources.getResourceByTypeAndKey(k.get_type(),k.get_key());
if(l){i=Array.indexOf(j._resources._array,l);
}});
return i;
},_getTimeSlotForAppointmentPart:function(k){var h=this._getRegularTimeSlotIndices(k.start);
var j=this._getTimeSlotDomElement(1,h.rowIndex,h.cellIndex,k.modelIndex);
var i=this._resources[k.modelIndex];
return this._createTimeSlot(h,k.start,j,i);
},_createTimeSlot:function(i,h,k,j){var l=60*24;
var m=(i.viewPartIndex==0)?l:this._owner.get_minutesPerRow();
return new e.ResourceGroupedWeekTimeSlot(i,h,m,j,k);
},_getTimeSlotDomElement:function(i,l,m,h){if(h===g){return this._weekModels[0]._getTimeSlotDomElement(i,l,m);
}if(this._isVertical){var j=this._weekModels[0].get_slotsPerDay();
if(i==0){l+=h;
}if(this._owner.get_showAllDayRow()&&i>0){l+=h+1;
}l+=j*h;
var k=this._owner.get_element();
return d("div.rsTopWrap table.rsContentTable",k)[0].tBodies[0].rows[l].cells[m];
}m+=this.get_numberOfDays()*h;
return this._weekModels[0]._getTimeSlotDomElement(i,l,m);
},_getRegularTimeSlotIndices:function(h){return this._weekModels[0]._getRegularTimeSlotIndices(h);
},_getAllDayTimeSlotIndices:function(h){return this._weekModels[0]._getAllDayTimeSlotIndices(h);
},_getMaxAppointmentGrowth:function(i){if(this._isVertical){var h=this.getTimeSlotFromDomElement(i);
return(this.get_slotsPerDay()-h.get_rawIndex().rowIndex-1);
}else{return e.ResourceGroupedWeekModel.callBaseMethod(this,"_getMaxAppointmentGrowth",[i]);
}},_createNestedModel:function(){return new e.WeekModel(this._owner);
},_getRawIndexFromDomElement:function(j){while(j&&(j.tagName.toUpperCase()!="TD")){j=j.parentNode;
}var h=j.parentNode;
var n=h.parentNode;
var i=this._weekModels[0]._getRawIndexFromDomElement(j);
var l;
if(this._isVertical){var k=n.rows.length/this._resources.get_count();
l=Math.floor(i.rowIndex/k);
i.rowIndex=i.rowIndex-(l*k);
if(this._owner.get_showAllDayRow()&&i.viewPartIndex>0){i.rowIndex--;
}i.modelIndex=l;
}else{var m=h.cells.length/this._resources.get_count();
l=Math.floor(i.cellIndex/m);
i.cellIndex=i.cellIndex-(l*m);
i.modelIndex=l;
}return i;
},_getAllDayTimeSlotForAppointmentPart:function(k){var h=this._getAllDayTimeSlotIndices(k.start);
h.viewPartIndex=0;
var j=this._getTimeSlotDomElement(h.viewPartIndex,h.rowIndex,h.cellIndex,k.modelIndex);
var i=this._resources[k.modelIndex];
return this._createTimeSlot(h,k.start,j,i);
},_getAllDayTimeSlotFromStartTime:function(k,h){var i=this._getAllDayTimeSlotIndices(k);
i.viewPartIndex=0;
var m=this._getAppointmentModelIndex(h);
var l=this._getTimeSlotDomElement(i.viewPartIndex,i.rowIndex,i.cellIndex,m);
var j=null;
var n=this;
h.get_resources().forEach(function(o){if(!j){j=n._resources.getResourceByTypeAndKey(o.get_type(),o.get_key());
}});
return this._createTimeSlot(i,k,l,j);
},_getTimeFromDomElement:function(h){var i=this._getRawIndexFromDomElement(h);
return this._weekModels[0]._getTimeFromIndex(i);
},removeFromBlock:function(h){this._weekModels[h.modelIndex].removeFromBlock(h);
},addToBlocks:function(h){this._weekModels[h.modelIndex].addToBlocks(h);
},_getRenderer:function(){if(!this._renderer){this._renderer=new e.Rendering.ResourceGroupedWeekViewRenderer(this);
}return this._renderer;
}};
e.ResourceGroupedWeekModel.registerClass("Telerik.Web.UI.Scheduler.ResourceGroupedWeekModel",e.WeekModelBase);
e.ResourceGroupedWeekTimeSlot=function(i,h,k,l,j){this._resource=l;
e.ResourceGroupedWeekTimeSlot.initializeBase(this,[i,h,k,j]);
};
e.ResourceGroupedWeekTimeSlot.prototype={get_index:function(){var h=this.get_rawIndex();
var i=e.ResourceGroupedWeekTimeSlot.callBaseMethod(this,"get_index");
return String.format("{0}:{1}",h.modelIndex,i);
},get_resource:function(){return this._resource;
}};
e.ResourceGroupedWeekTimeSlot.registerClass("Telerik.Web.UI.Scheduler.ResourceGroupedWeekTimeSlot",e.WeekTimeSlot);
})();
